package org.grow.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDiscoveryClient
public class GatewayRouteApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayRouteApplication.class, args);
    }


    public static final String UTILModule = "lb://TOOL-MS";
    public static final String PRETTYModule = "lb://PRETTY-MS";

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("a模块", r -> {
                    return r.path("/tool/**")
                            .uri(UTILModule);
                })
                .route("b模块", r -> {
                    return r.path("/pretty/**")
                            .uri(PRETTYModule);
                })
                .build();
    }
}
